package de.koller.aframe.gl;

import de.koller.aframe.util.physics.Location;
import de.koller.oceanFramework.math.RVec3;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.GLU;

public class Camera {

	public final RVec3 position = new RVec3( 0, 0, 0 );
	private RVec3 lookAt = new RVec3( 0, 0, 1 );
	private RVec3 alligment = null;
	public final RVec3 up = new RVec3( 0, 1, 0 );

	public void setTo( Location location, RVec3 eyeheight ) {
		position.set( location.position );
		position.add( eyeheight );
		
		this.setAlligment( location.alignment );
	}

	public void transformGL() {
		if( lookAt != null ) {
			GLU.gluLookAt( position.x, position.y, position.z, 
						   lookAt.x, lookAt.y, lookAt.z, 
					       up.x, up.y, up.z );
		} else if( alligment != null ) {
			GL11.glRotatef( (float)Math.toDegrees( -alligment.x ), 1, 0, 0 );
			GL11.glRotatef( (float)Math.toDegrees( -alligment.y ), 0, 1, 0 );
			GL11.glTranslatef( -position.x, -position.y, -position.z );
		}
	}

	public void setLookAt( RVec3 lookAt ) {
		this.lookAt = new RVec3( lookAt );
		this.alligment = null;
	}

	public void setAlligment( RVec3 alligment ) {
		this.alligment = new RVec3( alligment );
		this.lookAt = null;
	}
	
}
